<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller\User;
//use App\Controller\AbstractController;
use App\Controller\Core\ApiBaseController;
use App\Library\NetworkHelper;
use App\Model\User;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\DbConnection\Db;

/**
 * @Controller()
 * 这是user 模块下的view控制器的index方法
 */
class ViewController extends ApiBaseController
{
    /**
     * @RequestMapping(path="index", methods={"get", "post"})
     */
    public function index()
    {
//        $users = Db::select('SELECT * FROM user;');

        $users = User::findone(2);
        $user = $this->request->input('user', 'user Hyperf');
        $method = $this->request->getMethod();

        $result = [
            'method' => $method,
            'message' => "Hello {$user}.",
            'userlist' => $users,
        ];
        $result['url'] = NetworkHelper::siteUrl('https://baidu.com/','/news/index');
        return $this->handlesuccess($result);
    }
}
